home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 351-375 / disk_351 / pdc / libsrc.lzh / LibSrc / Math / cos.c < prev    next >
C/C++ Source or Header  |  1990-04-07  |  779b  |  40 lines

  1. #include <stdio.h>
  2. #include <math.h>
  3. #include "pml.h"
  4. #include "cordic.h"
  5.  
  6. static char     funcname[] = "cos";
  7.  
  8. extern CORDIC_Table CORDIC_Table0[1];
  9.  
  10. double
  11. cos(x)
  12.     double          x;
  13. {
  14.     int             Q;
  15.     double          x0, y0, z0;
  16.     double          D, t, temp;
  17.     struct exception xcpt;
  18.  
  19.     t = x / HALFPI;
  20.     D = modf(t, &temp);
  21.     Q = temp;
  22.     if (Q < 0)
  23.         Q = -Q;
  24.  
  25.     y0 = 0.0;
  26.     z0 = D * HALFPI;
  27.  
  28.     if (Q & 1) {
  29.         x0 = (Q & 2 ? 1.0 : -1.0);
  30.         CORDIC_rotate0(1, CORDIC_Table0, &x0, &y0, &z0);
  31.         xcpt.retval = y0 / CORDIC_Table0->kval;
  32.     }
  33.     else {
  34.         x0 = (Q & 2 ? -1.0 : 1.0);
  35.         CORDIC_rotate0(1, CORDIC_Table0, &x0, &y0, &z0);
  36.         xcpt.retval = x0 / CORDIC_Table0->kval;
  37.     }
  38.     return (xcpt.retval);
  39. }
  40.